module(..., package.seeall)
require "nvm"
require "mqttRestartOutMsg"
-- 初始化nvm获取配置参数
nvm.init("config.lua", true)
local clientNo = nvm.get("ClientNo")

--- MQTT客户端数据接收处理
-- @param mqttClient，MQTT客户端对象
-- @return 处理成功返回true，处理出错返回false
-- @usage mqttInMsg.proc(mqttClient)
function proc(mqttClient)
    local result, data, receiveMsg
    while true do
        result, data = mqttClient:receive(60000, "APP_SOCKET_SEND_DATA")
        log.info("result",result)
        -- 接收到数据
        if result then
            receiveMsg = data.payload
            log.info("mqttRstart payload", receiveMsg)
            log.info("data.topic", data.topic)
            if data.topic == "ACS/"..clientNo .. "/RESTART" or data.topic == "ACS/RESTART" then
                log.info("data.topicRestart")
                if receiveMsg == "restart" then
                    sys.restart("设备应急重启！")
                end
            end
        else
            break
        end
    end
    return result or data == "timeout" or data == "APP_SOCKET_SEND_DATA"
end
